<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/css/admin.css";?>" />
<script charset="UTF-8" src="/runtime/systemjs/jquery-1.4.4.min.js"></script>
<script charset="UTF-8" src="/runtime/systemjs/artdialog/artDialog.min.js"></script>
<script charset="UTF-8" src="/runtime/systemjs/form.js"></script>
<link rel="stylesheet" type="text/css" href="/runtime/systemjs/autovalidate/style.css"/><script charset="UTF-8" src="/runtime/systemjs/autovalidate/validate.js"></script>
<script type='text/javascript' src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/javascript/common.js";?>"></script>
<script type='text/javascript' src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/javascript/admin.js";?>"></script>
<script type='text/javascript' src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/javascript/menu.js";?>"></script>
</head>
<body>
<div class="container">
	<div id="header">
		<div id="menu">
			<ul name="menu">
			</ul>
		</div>
		<p><a href="<?php echo IUrl::creatUrl("/systemadmin/logout");?>">退出管理</a> <a href="<?php echo IUrl::creatUrl("/system/default");?>">后台首页</a> <a href="<?php echo IUrl::creatUrl("");?>" target='_blank'>商城首页</a> <span>您好 <label class='bold'><?php echo isset($this->admin['admin_name'])?$this->admin['admin_name']:"";?></label>，当前身份 <label class='bold'><?php echo isset($this->admin['admin_role_name'])?$this->admin['admin_role_name']:"";?></label></span></p>
	</div>
	<?php $admin_id = $this->admin['admin_id']?>
	<div id="info_bar"><label class="navindex"><a href="<?php echo IUrl::creatUrl("/system/navigation");?>">快速导航管理</a></label><span class="nav_sec">
	<?php $query = new IQuery("quick_naviga");$query->where = "adminid = $admin_id and is_del = 0";$items = $query->find(); foreach($items as $key => $item){?>
	<a href="<?php echo isset($item['url'])?$item['url']:"";?>" class="selected"><?php echo isset($item['naviga_name'])?$item['naviga_name']:"";?></a>
	<?php }?>
	</span></div>
	<div id="admin_left">
		<ul class="submenu">
		</ul>
		<div id="copyright">
			
		</div>
	</div>
	<?php $menu = new Menu();?>
	<script type='text/javascript'>
		var data = <?php echo $menu->submenu();?>;
		var current = '<?php echo $menu->current;?>';
		var url='<?php echo IUrl::creatUrl("/");?>';
		initMenu(data,current,url);
	</script>
	<div id="admin_right">
	<div class="headbar clearfix">
	<div class="position"><span>商品</span><span>></span><span>模型管理</span><span>></span><span>模型<?php if(isset($id)){?>编辑<?php }else{?>添加<?php }?></span></div>
	<ul class="tab" name="menu1">
		<li id="li_1" class="selected"><a href="javascript:selectTab('1');" hidefocus="true">基本信息</a></li>
		<li id="li_2"><a href="javascript:selectTab('2');" hidefocus="true">规格</a></li>
	</ul>
</div>

<form name="ModelForm" action="<?php echo IUrl::creatUrl("/goods/model_update");?>" method="post">
<div class="content_box">
	<div class="content form_content">
		<table id="tab-1" class="form_table" name="table">
			<col width="150px" />
			<col />
			<tr>
				<th>模型名称：</th>
				<td>
					<input class="normal" name="model_name" id="model_name" type="text" pattern="required" alt="模型名称不能为空！" value="<?php echo isset($name)?$name:"";?>"  /><label>* 模型名称（必填）</label>
					<input name="model_id" type="hidden" value="<?php echo isset($id)?$id:"";?>" />
				</td>
			</tr>
			<tr>
				<th>添加扩展属性：</th>
				<td><button class="btn" onclick="addAttr()" type="button"><span class="add">添加扩展属性</span></button></td>
			</tr>
			<tr>
				<td></td>
				<td>
					<table width="90%" class='border_table'>
						<thead>
							<tr>
								<th>属性名</th>
								<th nowrap="nowrap">前台列表页显示类型</th>
								<th>选择项可选值【选项之间用逗号','做分割】</th>
								<th>是否搜索</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="attr_list">
							<?php if(isset($model_attr)){?>
							<?php foreach($model_attr as $key => $item){?>
							<tr>
								<td><input name='attr[id][]' type='hidden' value="<?php echo isset($item['id'])?$item['id']:"";?>" /> <input name='attr[name][]' class='normal' type='text' value="<?php echo isset($item['name'])?$item['name']:"";?>" /></td>
								<td><select class="middle" name='attr[show_type][]'>
									<option value='1' <?php if($item['type'] =='1'){?> selected <?php }?>>单选框</option>
									<option value='2' <?php if($item['type'] =='2'){?> selected <?php }?>>复选框</option>
									<option value='3' <?php if($item['type'] =='3'){?> selected <?php }?>>下拉框</option>
									<option value='4' <?php if($item['type'] =='4'){?> selected <?php }?>>输入框</option>
								</select></td>
								<td><input class='normal' name='attr[value][]' type='text' value="<?php echo isset($item['value'])?$item['value']:"";?>" /></td>
								<td><input type='checkbox' <?php if($item['search'] == '1'){?> checked <?php }?> onclick="selectCheck(this,'is_search_'+<?php echo isset($key)?$key:"";?>)" />
									<input type='hidden' id="is_search_<?php echo isset($key)?$key:"";?>" name='attr[is_search][]' value="<?php echo isset($item['search'])?$item['search']:"";?>" /></td>
								<td><img class="operator" src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/images/admin/icon_del.gif";?>" alt="删除" onclick="delAttr(this)" /></td>
							</tr>
							<?php }?>
							<?php }?>
						</tbody>
					</table>
				</td>
			</tr>
		</table>
		<table id="tab-2" class="form_table" name="table" style="display: none">
			<col width="150px" />
			<col />
			<tr>
				<th>添加规格：</th>
				<td><button class="btn" onclick="addSpec()" type="button"><span class="add">添加规格</span></button></td>
			</tr>
			<tr>
				<td></td>
				<td>
					<table width="90%" class="border_table">
						<thead>
							<tr>
								<th>规格</th>
								<th>前台列表页显示类型</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="spec_list">
							<?php if(isset($model_spec)){?> <?php foreach($model_spec as $key => $item){?>
							<tr>
								<td>
									<input name='spec[id][]' type='hidden' value="<?php echo isset($item['id'])?$item['id']:"";?>" />
									<input name='spec[name][]' type='hidden' value="<?php echo isset($item['name'])?$item['name']:"";?>" />
									<input name='spec[note][]' type='hidden' value="<?php echo isset($item['note'])?$item['note']:"";?>" />
									<?php echo isset($item['name'])?$item['name']:"";?> [<?php echo isset($item['note'])?$item['note']:"";?>]
								</td>
								<td>
									<select class="middle" name='spec[show_type][]'>
										<option value='1' <?php if($item['show_type'] =='1'){?> selected <?php }?>>平铺显示</option>
										<option value='2' <?php if($item['show_type'] =='2'){?> selected <?php }?>>下拉显示</option>
									</select>
								</td>
								<td>
									<img class="operator" src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/images/admin/icon_asc.gif";?>" onclick="SpecOrder(0,this)" alt="向上" />
									<img class="operator" src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/images/admin/icon_desc.gif";?>" onclick="SpecOrder(-1,this)" alt="向下" />
									<img class="operator" src="<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/images/admin/icon_del.gif";?>" alt="删除" onclick="delAttr(this)" />
								</td>
							</tr>
							<?php }?> <?php }?>
						</tbody>
					</table>
				</td>
			</tr>
		</table>
		<table class="form_table">
			<col width="150px" />
			<col />
			<tr>
				<td></td>
				<td><button class="submit" type="button" onclick = "checkForm()"><span>保 存</span></button></td>
			</tr>
		</table>
	</div>
</div>
</form>
<script type='text/javascript'>
	//模型属性索引
	var index = <?php  echo isset($model_attr)? count($model_attr) :0?>;
	//添加一个模型属性
	function addAttr()
	{
		var str = "<tr>"+
					"<td><input name='attr[name][]'  class='normal' type='text' /><input name='attr[id][]' type='hidden' value='0' /></td>"+
					"<td><select class='middle' name='attr[show_type][]'>"+
						"<option value = '1'>单选框</option>"+
						"<option value = '2'>复选框</option>"+
						"<option value = '3'>下拉框</option>"+
						"<option value = '4'>输入框</option>"+
					"</select></td>"+
					"<td><input class='normal' name='attr[value][]' type='text'  /></td>"+
					"<td>"+
					"<input type='checkbox' value='1' onclick=\""+"selectCheck(this,'is_search_"+index+"')\" />"+
					"<input type='hidden' id = 'is_search_"+index+"'  name = 'attr[is_search][]' value = '0' /></td>"+
					"<td><img class='operator' src='<?php echo IUrl::creatUrl("")."views/".$this->theme."/skin/".$this->skin."/images/admin/icon_del.gif";?>' alt='删除'  onclick='delAttr(this)' /></td>"+
				"</tr>";
		$("#attr_list").append(str);
		index++;
	}
	//删除模型属性
	function delAttr(curr_attr)
	{
		$(curr_attr).parent().parent().remove();
	}
	//选择当前Tab
	function selectTab(curr_tab)
	{
		$("table[name='table']").hide();
		$("#tab-"+curr_tab).show();
		$("ul[name=menu1] > li").removeClass('selected');
		$('#li_'+curr_tab).addClass('selected');
	}
	//添加模型规格
	function addSpec()
	{
		art.dialog.load('<?php echo IUrl::creatUrl("/block/spec_list");?>', {
			id:'add_spec',
			lock: true,
		    title: '选择规格'

		}, true);
	}
	//设置选择复选框的值
	function selectCheck(curr_check,change_control)
	{
		if($(curr_check).attr("checked"))
		{
			$("#"+change_control).val("1");
		}
		else
		{
			$("#"+change_control).val("0");
		}
	}
	//模型属性表单验证
	function checkForm()
	{
		var model_name = $('#model_name').val();
		if(model_name=='')
		{
			selectTab(1);
		}
		var isPass = true;
		//验证模型属性名字
		$("input[name='attr[name][]']").each(function(i,obj){
			$(this).removeClass(" invalid-text");
			if(!validate($(this).val(),'required'))
			{
				alert("属性名字不能为空！");
				$(this).addClass(" invalid-text");
				isPass = false;
				return false;
			}
		});
		//验证模型属性值
		$("input[name='attr[value][]']").each(function(i,obj){
			$(this).removeClass(" invalid-text");
			if(!validate($(this).val(),'required'))
			{
				alert("属性值不能为空！");
				$(this).addClass(" invalid-text");
				isPass = false;
				return false;
			}
		});
		//onsubmit事件在submit之前，所以先判断onsubmit事件是否成功。
		if(document.ModelForm.onsubmit()!=false && isPass)
			document.ModelForm.submit();
	}

	//规格排序
	function SpecOrder(type,curr)
	{
		if(type==0)
		{
			var insertIndex = $(curr).parent().parent().prev().index();
			if(insertIndex >= 0)
			{
				$('#spec_list tr:eq('+insertIndex+')').before($(curr).parent().parent());
			}
		}
		else
		{
			var insertIndex = $(curr).parent().parent().next().index();
			$('#spec_list tr:eq('+insertIndex+')').after($(curr).parent().parent());
		}
	}
</script>
	</div>
	<div id="separator"></div>
</div>
<script type='text/javascript'>
	//隔行换色
	$(".list_table tr::nth-child(even)").addClass('even');
	$(".list_table tr").hover(
		function () {
			$(this).addClass("sel");
		},
		function () {
			$(this).removeClass("sel");
		}
	);
	$(function(){
		 $('#headth th').each(function(i){
			var width = $('#headth th:eq('+i+')').width();
			$('#conth tr:eq(0) td:eq('+i+')').width(width-2);
		});
	});
</script>
</body>
</html>
